<?php
require('../database/db.php');
$mysql=new mysql();
// 传入参数
$userid=$_REQUEST['userid'];
// $shopid=$_REQUEST['shopid'];
// 传入参数 end

$state=0;
$state3=3;

if ($userid) {
	$sql="select carid,goodsid,fTitle,sTitle,price,number,shopid from car where userid='".$userid."' and (state='".$state."' or state='".$state3."')";
	$car=$mysql->getAll($sql);
	$allCar = array();
	foreach ($car as $k => $v) {
		
		$sql="select title,images,zixilie,start_num from goods where goodsid=".$v[goodsid];

		$goods=$mysql->getRow($sql);
		$v[goodstitle] = $goods[title];
		$v[start_num] = $goods[start_num];

		$sql="select * from shop where shopid=".$v[shopid];
		$shop=$mysql->getRow($sql);
		// 查找商品类型（海淘或快购）
		$sql = "select type from zifenlei where id=".$goods[zixilie];
		$type=$mysql->getOne($sql);

		$v[type]=$type;
		// 查找商品类型（海淘或快购） end
		
		$v[shopname]=$shop[name];
		//$v[start_price]=$shop[start_price];
		$v[distribution_fee]=$shop[distribution_fee];
		$v[song_da]=$shop[song_da];
		$v[goodsimages]=explode(',', $goods[images]);

		// 查找买家服务
		$query = mysql_query("select htservice,kgservice,distribution_fee from shop where shopid=".$shop[shopid]);
		$shop = mysql_fetch_assoc($query);
		$htservice = explode(',', $shop[htservice]);
		$htlen = count($htservice);
		$services = array();
		for ($i=0; $i < $htlen; $i++) { 
			$sql = mysql_query("select name from buyer_service where id=".$htservice[$i]);
			$shop = mysql_fetch_assoc($sql);
			$services[] = $shop[name];
		}
		$v[services]=$services;
       // 查找买家服务 end

		$allCar[$v[shopid]][] = $v;
	}
    
	/*if (empty($allCar)) {
		$allCar[data] = 1;
	}*/
	$dataArray = array();
	$i=0;
	foreach ($allCar as $key => $value) {
		$goodsArray = $value;
		$dataArray[$i][shopid] = $key;
		foreach ($goodsArray as $key1 => $value1) {
            $dataArray[$i][shopname] = $value1[shopname];
            $dataArray[$i][goods_list][] = $value1;
	  }
	  $i++;
	}
	$arr = array('code' => 200, 'msg' =>'查询成功,需要传入参数:必传参数用户id=>userid;' ,'data' =>$dataArray);
}else{
	$arr = array('code' => -100, 'msg' =>'参数传入有误,需要传入参数:必传参数用户id=>userid;');
}
echo json_encode($arr);